package com.quanyan.order.mapper;

import com.quanyan.order.entity.PlatformOrderQueryParamsVo;
import com.quanyan.order.vo.OrderQueryRespVo;
import com.quanyan.order.vo.PlatformOrderQueryRespVo;
import com.quanyan.order.entity.update.ApplyOrderRefund;
import com.quanyan.order.vo.PlatformOrderQueryTotalAmount;
import com.quanyan.order.vo.TimeoutOrderVo;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author songzj
 * @date 16/6/13-11:33
 */
public interface UOrderMapper {



    /**
     * 用户申请退款
     * 1) 增加退款中金额, 且 退款中金额 + 已退款金额 <= 支付金额
     * 2) 退款订单必须是已确认, 已支付的.
     * update tb_order
     * set
     * refund_ing_amount = refund_ing_amount + 20,
     * refund_state = case  when pay_amount > (refund_ing_amount + 20 + refund_amount) then 1
     * when pay_amount <= (refund_ing_amount + 20 + refund_amount) then 2
     * end
     * where pay_amount >= (refund_ing_amount + 20 + refund_amount)
     * and pay_state = 1
     * and order_state =1
     * and order_no = '11215876199099000210';
     * @return
     */
    int updateApplyOrderRefund(ApplyOrderRefund applyOrderRefund);

    /**
     * 退款失败处理
     * @param orderNo
     * @param refundAmount
     * @return
     */
    int orderRefundFail(@Param("orderNo")String orderNo,@Param("refundAmount")BigDecimal refundAmount);

    /**
     * 退款成功处理
     * @param orderNo
     * @param refundAmount
     * @return
     */
    int orderRefundSuccess(@Param("orderNo")String orderNo,@Param("refundAmount")BigDecimal refundAmount);

    /**
     * 获取超时未支付的订单
     * @param begin
     * @param pageSize
     * @return
     */
    List<TimeoutOrderVo> findTimeoutOrderVo(@Param("begin") int begin,
                                            @Param("pageSize") int pageSize);

    /**
     * 获取平台订单
     * @return
     */
    List<PlatformOrderQueryRespVo> findPlatformOrderQueryRespVo(PlatformOrderQueryParamsVo paramsVo);

    /**
     * 获取平台订单总数
     * @param paramsVo
     * @return
     */
    int getPlatformOrderQueryRespVoTotalCnt(PlatformOrderQueryParamsVo paramsVo);

    /**
     * 获取平台订单总金额
     * @param paramsVo
     * @return
     */
    PlatformOrderQueryTotalAmount getPlatformOrderQueryTotalAmount(PlatformOrderQueryParamsVo paramsVo);


    /**
     * 根据orderNo查找相关信息
     * @param orderNo
     * @return
     */
    OrderQueryRespVo getOrderQueryByOrderNo(@Param("orderNo") String orderNo);


    BigDecimal getNoDisTotalOrderAmount(PlatformOrderQueryParamsVo paramsVo);

    BigDecimal getOverOrderAmount(PlatformOrderQueryParamsVo paramsVo);

    BigDecimal getNoDisPayAmount(PlatformOrderQueryParamsVo paramsVo);

    BigDecimal getOverPayAmount(PlatformOrderQueryParamsVo paramsVo);

    BigDecimal getTotalRefundAmount(PlatformOrderQueryParamsVo paramsVo);
}
